package Builder;

class Product {
    private String partA;
    private String partB;
    private String partC;

    public String getPartA() {
        return partA;
    }

    public void setPartA(String partA) {
        this.partA = partA;
    }

    public String getPartB() {
        return partB;
    }

    public void setPartB(String partB) {
        this.partB = partB;
    }

    public String getPartC() {
        return partC;
    }

    public void setPartC(String partC) {
        this.partC = partC;
    }
    public void show(){
        //显示产品的特性
        System.out.println(partA+"  "+partB+" "+partC);
    }
}
//抽象构建者：包含创建产品各个子部件的抽象方法
abstract class Builder{
    //创建产品类
    protected Product product = new Product();
    public abstract void buildPartA();
    public abstract void buildPartB();
    public abstract void buildPartC();
    //返回产品对象
    public Product getProduct(){
        return product;
    }
}
//具体建造者：实现抽象的建造接口
public class ConcreateBuilder extends Builder{

    @Override
    public void buildPartA() {
        product.setPartA("建造partA");
    }

    @Override
    public void buildPartB() {
        product.setPartB("建造partC");
    }

    @Override
    public void buildPartC() {
        product.setPartC("建造partC");
    }
}
//指挥者：调用建造者的方法完成复杂对象的创建
class Director{
    private Builder builder;
    public Director(Builder builder){
        this.builder = builder;
    }
    //产品构建与组装
    public Product construct(){
        builder.buildPartA();
        builder.buildPartB();
        builder.buildPartC();
        return builder.getProduct();
    }
}

